/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    dw_wdt.h
 *  @brief   Designware watchdog driver header
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#ifndef __DW_WDT_H__
#define __DW_WDT_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "bits.h"
#include "dev_common.h"

#define DW_WDT_CR_EN                    BIT(0)
#define DW_WDT_CR_RMOD                  BIT(1)
#define DW_WDT_RESTART_KICK_VAL         0x76
#define DW_WDT_DEF_TIMEOUT              0
#define DW_WDT_DEF_PRETIMEOUT           30

struct dw_wdt {
	volatile uint32_t wdt_cr;
	volatile uint32_t wdt_torr;
	const volatile uint32_t wdt_ccvr;
	volatile uint32_t wdt_crr;
	const volatile uint32_t wdt_stat;
	const volatile uint32_t wdt_eoi;
	uint32_t padding_1;
	volatile uint32_t wdt_prot_level;
	uint32_t padding_2[49];
	const volatile uint32_t wdt_comp_param_5;
	const volatile uint32_t wdt_comp_param_4;
	const volatile uint32_t wdt_comp_param_3;
	const volatile uint32_t wdt_comp_param_2;
	const volatile uint32_t wdt_comp_param_1;
	const volatile uint32_t wdt_comp_version;
	const volatile uint32_t wdt_comp_type;
};

enum wdt_port {
	eDW_WDT_0,
	eDW_WDT_1,
	eDW_WDT_MAX,
};

enum dw_wdt_rmod {
	DW_WDT_RMOD_RESET = 1,
	DW_WDT_RMOD_IRQ = 2,
};

void wdt_switch(enum wdt_port wdt);
void wdt_init(void);
void wdt_start(uint32_t timeout);
void wdt_stop(void);
void wdt_ping(void);
uint32_t wdt_get_timeout(void);
uint32_t wdt_get_timeleft(void);
void wdt_isr(void *args);
void wdt_register_callback(DEV_CALLBACK callback);

#ifdef __cplusplus
}
#endif

#endif /* __DW_WDT_H__ */

